package simulate;

import java.util.HashMap;
import java.util.Map;

public class minNumberOfFrogs {
    //数青蛙
    public int minNumberOfFrogs(String croakOfFrogs) {
        int[] hash=new int[5];
        int n=hash.length;
        char[] s=croakOfFrogs.toCharArray();
        Map<Character,Integer> t=new HashMap<>();

        String ss="croak";
        for(int i=0;i<ss.length();i++){
            t.put(ss.charAt(i),i);
        }

        for(char ch : s){
            if(ch==ss.charAt(0)){
                if(hash[n-1]!=0){
                    hash[n-1]--;
                }
                hash[0]++;
            }else{
                int i=t.get(ch);
                if(hash[i-1]==0) return -1;
                hash[i-1]--;
                hash[i]++;
            }
        }
        for(int i=0;i<hash.length-1;i++){
            if(hash[i]!=0){
                return -1;
            }
        }
        return hash[n-1];
    }
}
